package com.xx.job.controller.system;


import com.xx.job.common.Result;
import com.xx.job.entity.system.SysMenu;
import com.xx.job.service.system.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import com.xx.job.controller.base.BaseController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liangcy
 * @since 2021-01-14
 */
@RestController
@RequestMapping("/api/v1")
public class SysMenuController extends BaseController {

    @Autowired
    private SysMenuService sysMenuService;

    @RequestMapping("/menurole")
    public Result menurole(HttpServletRequest request){
        List<SysMenu> menuData = sysMenuService.getMenuData(request);
        return Result.success(menuData);
    }

    @GetMapping("/menulist")
    public Result menulist(@RequestParam(value = "title",required = false) String title,@RequestParam(value = "visible",required = false) String visible){
        List<SysMenu> menuData = sysMenuService.menulist(title,visible);
        return Result.success(menuData);
    }

    @GetMapping("/menuTreeselect")
    public Result menuTreeselect(){
        List<Map<String,Object>> menuData = sysMenuService.menuTreeselect();
        return Result.success(menuData);
    }

    @PostMapping("/menu")
    public Result addMenu(@RequestBody SysMenu sysMenu){
        return Result.success(sysMenuService.add(sysMenu));
    }

    @GetMapping("/menu/{id}")
    public Result selectMenu(@PathVariable Long id){
        return Result.success(sysMenuService.select(id));
    }

    @DeleteMapping("/menu/{id}")
    public Result deleteMenu(@PathVariable Long id){
        return Result.success(sysMenuService.delete(id));
    }

    @PutMapping("/menu")
    public Result updateMenu(@RequestBody SysMenu sysMenu){
        return Result.success(sysMenuService.update(sysMenu));
    }



}

